package com.dragon.annoations;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 验证注解的测试方法
 *
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/6/8 10:51
 */
@AuthorityAnnoation(describe = "我是注解类")
public class AnnotationTest {

    @AuthorityAnnoation(name = "张三", describe = "我是注解属性")
    public Object object;

    @AuthorityAnnoation(describe = "我是注解方法")
    public void test() {
        System.out.println("注解方法被执行了");
    }

    public static void main(String[] args) throws NoSuchFieldException {
        Field field = AnnotationTest.class.getField("object");
        AuthorityAnnoation annotation = field.getAnnotation(AuthorityAnnoation.class);
        System.out.println(annotation.name());
        System.out.println(annotation.describe());
        System.out.println(annotation.id);
        System.out.println("---------------------------------------------------");
        Method[] methods = AnnotationTest.class.getMethods();
        for (Method method : methods) {
            boolean flag = method.isAnnotationPresent(AuthorityAnnoation.class);
            if (flag) {
                AuthorityAnnoation anno = method.getAnnotation(AuthorityAnnoation.class);
                System.out.println(anno.describe());
            }
        }
    }
}
